<!DOCTYPE html>
<html><head>
	    <meta charset="utf-8">
    <title>ThinkPHP5.0</title>

    <meta name="description" content="Dashboard">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--Basic Styles-->
    <link href="__ADMIN__/style/bootstrap.css" rel="stylesheet">
    <link href="__ADMIN__/style/font-awesome.css" rel="stylesheet">
    <link href="__ADMIN__/style/weather-icons.css" rel="stylesheet">

    <!--Beyond styles-->
    <link id="beyond-link" href="__ADMIN__/style/beyond.css" rel="stylesheet" type="text/css">
    <link href="__ADMIN__/style/demo.css" rel="stylesheet">
    <link href="__ADMIN__/style/typicons.css" rel="stylesheet">
    <link href="__ADMIN__/style/animate.css" rel="stylesheet">
    <script src="__ADMIN__/ueditor/ueditor.config.js"></script>
    <script src="__ADMIN__/ueditor/ueditor.all.min.js"></script>
    <script src="__ADMIN__/ueditor/lang/zh-cn/zh-cn.js"></script> 
    
     <script src="__ADMIN__/style/jquery_002.js"></script>
    <script src="__ADMIN__/org/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#uploadify").uploadify({
                //指定swf文件
                'swf': '__ADMIN__/org/uploadify/uploadify.swf',
                //后台处理的页面
                'uploader': "{:url('document/upload')}",
                'progressData' : 'speed',
                //按钮显示的文字
                'buttonText': '上传文件',
                //按钮样式自主选择
                'buttonClass':'btn btn-magenta shiny',
                //设定发送数据的name值
                'fileObjName':'thumb',
                //显示的高度和宽度，默认 height 30；width 120
                //'height': 15,
                //'width': 80,
                //上传文件的类型  默认为所有文件    'All Files'  ;  '*.*'
                //在浏览窗口底部的文件类型下拉菜单中显示的文本
                'fileTypeDesc': 'Image Files',
                'auto': true,
                'onUploadSuccess' : function(file, data, response) {
                    $("input[name='thumb']").val(data);  
                    var documentimgsrc="__index__/uploads/documentimg/"+data;
                    var documentimg="<img height='60' src='"+documentimgsrc+"'>";
                    $("#documentimgdiv").show();
                    $("#documentimg").html(documentimg);
                    }
            });
            $("#uploadify-button").prepend("<i style='padding-right:4px;' class='fa fa-upload'></i>");
            $("#uploadify-button").removeAttr('style');
        });

    </script>
</head>
<body>
	 {include file="public/header"}
    <!-- /头部 -->
    
    <div class="main-container container-fluid">
        <div class="page-container">
                        <!-- Page Sidebar -->
            {include file="public/left"}
            <!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                                        <li>
                        <a href="{:url('index/index')}">系统</a>
                    </li>
                                        <li>
                        <a href="{:url('document/lst')}">文档管理</a>
                    </li>
                                        <li class="active">编辑文档</li>
                                        </ul>
                </div>
                <!-- /Page Breadcrumb -->

                <!-- Page Body -->
                <div class="page-body">
                    
<div class="row">
    <div class="col-lg-12 col-sm-12 col-xs-12">
        <div class="widget">
            <div class="widget-header bordered-bottom bordered-blue">
                <span class="widget-caption">编辑文档</span>
            </div>
            <div class="widget-body">
                <div id="horizontal-form">
                    <form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="id" value="{$artRes.id}">
                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label no-padding-right">文章标题</label>
                            <div class="col-sm-6">
                                <input class="form-control" id="" value="{$artRes.title}" name="title" required="" type="text">
                            </div>
                            <p class="help-block col-sm-4 red">* 必填</p>
                        </div>

                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label no-padding-right">文章属性</label>
                            <div class="col-sm-6">
                                  <?php 
                                  $attr=$artRes['attr'];
                                  $attr=explode(',',$attr);
                                  ?> 
                                <div class="checkbox" style="float:left;padding-left:5px">
                                    <label>
                                        <input  name="attr[]" value="头条" type="checkbox" <?php if(in_array('头条',$attr)){ echo 'checked="checked"';} ?> class="colored-blue">
                                        <span class="text">头条</span>
                                    </label>
                                </div>
                                 <div class="checkbox" style="float:left;padding-left:15px">
                                    <label>
                                        <input name="attr[]" value="推荐" type="checkbox" <?php if(in_array('推荐',$attr)){ echo 'checked="checked"';} ?>  class="colored-green">
                                        <span class="text">推荐</span>
                                    </label>
                                </div>
                                <div class="checkbox" style="float:left;padding-left:15px">
                                    <label>
                                        <input name="attr[]" value="幻灯" type="checkbox" <?php if(in_array('幻灯',$attr)){ echo 'checked="checked"';} ?>  class="colored-bule">
                                        <span class="text">幻灯</span>
                                    </label>
                                </div>
                                <div class="checkbox" style="float:left;padding-left:15px">
                                    <label>
                                        <input name="attr[]" value="加粗" type="checkbox" <?php if(in_array('加粗',$attr)){ echo 'checked="checked"';} ?>  class="colored-bule">
                                        <span class="text">加粗</span>
                                    </label>
                                </div>
                                <div class="checkbox" style="float:left;padding-left:15px">
                                    <label>
                                        <input name="attr[]" value="图片" type="checkbox" <?php if(in_array('图片',$attr)){ echo 'checked="checked"';} ?>  class="colored-bule">
                                        <span class="text">图片</span>
                                    </label>
                                </div>
                            </div>  
                        </div>
                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label no-padding-right">所属栏目</label>
                            <div  class="col-sm-6">
                                    {volist name="cateres" id="v"}
                                     {if condition="$artRes['cate_id'] eq $v['id']"} 
                                        <input readonly="readonly" class="form-control"  name="cate_id" required="" type="text" value="{$v.cate_name}" >
                                     <input type="hidden" name="cate_id" value="{$v.id}">
                                      {/if} 
                                    {/volist}
                                </select> 

                            </div>
                            <p class="help-block col-sm-4 red">* 必填</p>
                        </div>

                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label no-padding-right">文章关键词</label>
                            <div class="col-sm-6">
                                <input class="form-control" id="" placeholder="" name="keywords" value="{$artRes.keywords}" required="" type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label no-padding-right">文章描述</label>
                            <div class="col-sm-6">
                                <textarea name="description" id="" class="form-control">{$artRes.description}</textarea>
                            </div>
                            <p class="help-block col-sm-4 red">* 必填</p>
                        </div>

                        
                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label no-padding-right">作者</label>
                            <div class="col-sm-6">
                                <input class="form-control" id="" placeholder="" name="author" value="{$artRes.author}" required="" type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label no-padding-right">文章来源</label>
                            <div class="col-sm-6">
                                <input class="form-control" id="" placeholder="" name="source" value="{$artRes.source}" required="" type="text">
                            </div>

                        </div>

                        <div class="form-group">
                           <label for="username" class="col-sm-2 control-label no-padding-right">缩略图</label>
                           <div class="col-sm-6" style="margin-top:4px">
                            <label >
                               <span id="uploadify"></span>
                               <input type="hidden"  name="thumb" value="{$artRes['thumb']}" >
                           </label>
                           <label >
                               <div id="cancel"  class="uploadify-button btn btn-magenta shiny" style="float: left;margin-left:10px"><span class="uploadify-button-text"><i style="padding-right:4px" class="fa fa-rotate-left"></i>撤销上传</span></div>
                           </label>
                           </div>
                   </div>
                    
                    <div class="form-group" id="documentimgdiv" {if condition="$artRes['thumb'] eq ''"} style="display: none;" {/if}>
                        <label for="username" class="col-sm-2 control-label no-padding-right"></label>
                        <div class="col-sm-6" style="margin-top:4px">
                         <label id="documentimg">
                         {if condition="$artRes['thumb'] neq ''"}  
                            <img height="100" src="__index__/uploads/documentimg/{$artRes['thumb']}" alt="">
                         {/if}
                        </label>
                        </div>
                    </div>

                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label no-padding-right">点击量</label>
                            <div class="col-sm-6">
                                <input class="form-control" id="" placeholder="" name="click" value="{$artRes.click}" required="" type="text">
                            </div>
                        </div>
                        <!-- 自定义字段开始 -->
                        <?php foreach($field as $k=>$v):?>
                            <div class="form-group">
                                <label for="username" class="col-sm-2 control-label no-padding-right">{$v.field_cnname}</label>
                                <div class="col-sm-6">
                                <!-- 1,文本输入框；2单选按钮3,复选框4,下拉菜单5,文本域6,附件类型 7浮点型 8、整形 9.长文本类型longtext-->
                                    <?php switch ($v['field_type']) {
                                        case 1:
                                        case 7:
                                        case 8:
                                           echo "<input value='".$data[$v['field_enname']]."' class='form-control' name='".$v['field_enname']."' type='text'>";
                                            break;
                                        case 5:
                                           echo "<textarea class='form-control' name='".$v['field_enname']."'>".$data[$v['field_enname']]."</textarea>";
                                            break;
                                        case 2:
                                            if($v['field_values']){
                                                $valuesArr=explode(',',$v['field_values']);          foreach($valuesArr as $k1=>$v1){
                                                if($data[$v['field_enname']] ==$v1){
                                                    $check="checked='checked'";
                                                }else{
                                                    $check='';
                                                }
                                                echo " <div class='control-group'>
                                                <div class='radio' style='float:left;margin-left:15px'> <label>";
                                                 echo "<input ".$check." value='".$v1."' name='".$v['field_enname']."' type='radio' class='colored-blue'>";  
                                                echo "<span class='text'> $v1</span> </label></div> </div>";
                                                }
                                            }
                                            
                                            break;
                                        case 3:
                                          if($v['field_values']){
                                            $values=explode(',',$v['field_values']);
                                            $datarr=explode(',',$data[$v['field_enname']]);
                                            foreach($values as $k2=>$v2){
                                                if(in_array($v2, $datarr)){
                                                    $check="checked='checked'";
                                                }else{
                                                    $check='';
                                                }
                                                echo "<div class='checkbox'  style='float:left;padding-left:15px'><label>";
                                                echo "<input ".$check." name='".$v['field_enname'].'[]'."' value='".$v2."' type='checkbox' class='colored-blue'>";
                                                echo "<span class='text'>$v2</span></label></div>"; 
                                                }
                                            }
                                           break;
                                        case 4:
                                            if($v['field_values']){
                                                echo "<select name='".$v['field_enname']."' id=''><option value=''>请选择</option>";
                                                $valuesArr=explode(',',$v['field_values']);
                                                foreach($valuesArr as $k1=>$v1){
                                                    if($data[$v['field_enname']] ==$v1){
                                                        $select="selected='selected'";
                                                    }else{
                                                        $select='';
                                                    }
                                                   echo "<option ".$select." value='$v1'>$v1</option>";
                                                }
                                                echo "</select>";
                                             }
                                            break;
                                        case  6:
                                            echo " <input value='".$data[$v['field_enname']]."' style='float:left;' name='".$v['field_enname']."'  type='file'>";
                                             if($data[$v['field_enname']]){
                                                echo "<img height='60' src='__index__/uploads/att/".$data[$v['field_enname']]."' alt=''>
                                                <a onclick='delimg(this);' href='javascript:;'><span class='label label-success'>
                                                删除 </span></a>  ";
                                            }
                                            break;
                                        case  9:
                                            echo get_ueditor($v['field_enname'],$data[$v['field_enname']]);
                                            break;
                                        default:
                                            echo "<input value='".$data[$v['field_enname']]."' class='form-control' name='".$v['field_enname']."' type='text'>";
                                            break;
                                    } ?>
                                </div>
                            </div>
                        <?php endforeach;?>
                        <!-- 自定义字段结束 -->
                            <!-- 自定义图片删除 -->
                        <script>
                            function delimg(obj){
                                 layer.confirm('确定要删除图片吗？', {icon: 3, title:'提示'}, function(index){
                                        var img=$(obj).prev();
                                        var input=img.prev();
                                        var field_name=input.attr('name');
                                        var imgSrc=input.attr('value');
                                        img.remove();
                                        $(obj).remove();
                                        var aid="{$aid}";
                                        var modelid="{$modelid}";   
                                         $.ajax({
                                            type:"post",
                                            dataType:"json",
                                            data:{aid:aid,modelid:modelid,field_name:field_name,imgSrc:imgSrc},
                                            url:"{:url('document/ajaximg')}",
                                            success:function(data){
                                                //alert(data);
                                                if(data ==1){
                                                    layer.msg('删除图片成功！', {icon: 6});
                                                }else{
                                                    layer.msg('删除图片失败！', {icon: 5});
                                                }
                                                }
                                            });
                                  layer.close(index);
                                });
                            }
                        </script>
                        <!-- /自定义图片删除 -->
                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label no-padding-right">文章内容</label>
                            <div class="col-sm-6">
                                <textarea name="content" id="content" >{$artRes.content}</textarea>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn btn-default">保存信息</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->
		</div>	
	</div>

	    <!--Basic Scripts-->

    <script src="__ADMIN__/style/bootstrap.js"></script>
    <script src="__ADMIN__/style/jquery.js"></script>
     <script src="__ADMIN__/org/layer/layer.js"></script>
    <!--Beyond Scripts-->
    <script src="__ADMIN__/style/beyond.js"></script>
    <script type="text/javascript">
       
   
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    
    UE.getEditor('content',{toolbars: [[
            'fullscreen', 'source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', 
            'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
            'simpleupload', 'insertimage', 'emotion', 
        ]
        ],initialFrameWidth:600,initialFrameHeight:300,});

    $("#cancel").click(function(){
            var imgurl=$("input[name='thumb']").val();
            if(!imgurl){
                layer.msg('请先上传图片！', {icon: 2});
                return false;
            }
            /*if(!confirm('确定要撤销图片吗？')){
                return false;
            }*/
            layer.confirm('确定要撤销图片吗？', {icon: 3, title:'提示'}, function(index){
                  //do something
                    $("input[name='thumb']").val('');
                    $("#documentimgdiv").hide();
                    $.ajax({
                    type:"post",
                    dataType:"json",
                    data:{imgurl:imgurl},
                    url:"{:url('document/delimg')}",
                    success:function(data){
                        //alert(data);
                        if(data.status == 0){
                            layer.msg(data.msg, {icon: 6});
                        }else{
                            layer.msg(data.msg, {icon: 5});
                        }
                    }
                    });
          layer.close(index);
        });
            
    }); 


    </script>

</body></html>